namespace CISLib.EncryptClasses
{
    using System;
    using System.Security.Cryptography;
    using System.Text;

    public class MACTripleDESEncrypt
    {
        private byte[] __data = null;
        private string __key = "ksn168ch";
        private MACTripleDES mact = new MACTripleDES();

        public string GetHashValue()
        {
            if (this.Data == null)
            {
            }
            byte[] key = Encoding.ASCII.GetBytes(this.Key);
            this.mact.Key = key;
            byte[] hash_b = this.mact.ComputeHash(this.mact.ComputeHash(this.Data));
            return Encoding.ASCII.GetString(hash_b);
        }

        public byte[] Data
        {
            get
            {
                return this.__data;
            }
            set
            {
                this.__data = value;
            }
        }

        public string Key
        {
            get
            {
                return this.__key;
            }
            set
            {
                int keyLength = value.Length;
                int[] keyAllowLengths = new int[] { 8, 0x10, 0x18 };
                bool isRight = false;
                foreach (int i in keyAllowLengths)
                {
                    if (keyLength == keyAllowLengths[i])
                    {
                        isRight = true;
                        break;
                    }
                }
                if (!isRight)
                {
                    throw new ApplicationException("用于数字签名的密钥长度必须是8,16,24值之一");
                }
                this.__key = value;
            }
        }
    }
}

